home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / tarsrc Folder / dir.c < prev    next >
Text File  |  1991-08-06  |  3KB  |  144 lines

  1. /*
  2.  * Macintosh Tar
  3.  *
  4.  * dir.c - routines dealing with directory selection
  5.  *
  6.  * NOTE: I think the worst thing lacking is a SFGetDirectory dialog.
  7.  *     It isn't clear at all what is valid in the reply structure
  8.  *     if an open is faked.  I don't vouch for this code, but it
  9.  *     seems to work.
  10.  *
  11.  * Written by Craig Ruff
  12.  */
  13.  
  14. #include "tar.h"
  15. #include <SysEqu.h>
  16.  
  17. #define ROOTDIR        2        /* WATCH OUT!  Subject to change? */
  18.  
  19. #define dirID        130        /* Directory selection dialog */
  20. #define selectItem    11        /* Select directory button */
  21.  
  22. WDPBRec        wdpb;
  23. Boolean        dirSelected;        /* True if 'Select' button used, next two vars set */
  24. short        dirVRefNum;        /* Selected directory VRefNum */
  25. long        dirDirID;        /* Selected directory DirID */
  26.  
  27. pascal short
  28. DialogHook(item, theDialog)
  29. short        item;
  30. DialogPtr    theDialog;
  31. {
  32. #pragma unused(theDialog)
  33.  
  34.     switch (item) {
  35.     case selectItem:
  36.         dirSelected = true;
  37.         item = getOpen;
  38.         /* fall through */
  39.         
  40.     case getOpen:
  41.         /*
  42.          * Kludge!  Access low memory.
  43.          * This should be supplied in
  44.          * the reply structure!!
  45.          */
  46.         dirVRefNum = -*(short *) SFSaveDisk;
  47.         dirDirID = *(int *) CurDirStore;
  48.         break;
  49.     }
  50.     
  51.     return(item);
  52. }
  53.  
  54. /*
  55.  * GetDir - manage the directory selection dialog
  56.  */
  57. Boolean
  58. GetDir(prompt, extract)
  59. char    *prompt;
  60. Boolean    extract;
  61. {
  62.     Point        where;
  63.     SFReply        reply;
  64.     HParamBlockRec    volpb;
  65.     char        *routine = "\pGetDir";
  66.  
  67.     where.h = where.v = 75;
  68.     dirSelected = false;
  69.     SFPGetFile(where, prompt, nil, -1, nil, DialogHook, &reply, dirID, nil);
  70.     if (!reply.good)
  71.         return(false);
  72.  
  73.     /*
  74.      * Make sure the volume we are dealing with is a HFS volume.
  75.      */
  76.     volpb.volumeParam.ioCompletion = nil;
  77.     volpb.volumeParam.ioNamePtr = nil;
  78.     volpb.volumeParam.ioVRefNum = dirVRefNum;
  79.     volpb.volumeParam.ioVolIndex = 0;
  80.     PBHGetVInfo(&volpb, false);
  81.     if (volpb.volumeParam.ioResult != noErr) {
  82.         OSAlert(routine, "\pPBHGetVInfo", nil,
  83.                 volpb.volumeParam.ioResult);
  84.         return(false);
  85.     }
  86.  
  87.     if (volpb.volumeParam.ioVSigWord != 0x4244) {
  88.         HFSAlert();
  89.         return(false);
  90.     }
  91.     
  92.     /*
  93.      * For creation, rely on SFPGetFile providing the directory's VRefNum
  94.      * and DirID via the low memory variables.
  95.      */
  96.     if (!extract)
  97.         return(true);
  98.         
  99.     /*
  100.      * If we are extracting, we only need a working directory vRefNum.
  101.      */
  102.     if (!dirSelected) {
  103.          /* Real file selected, SFPGetFile provides this for us. */
  104.         dirVRefNum = reply.vRefNum;
  105.         
  106.     } else {
  107.         /*
  108.          * We have a pseudo selection.  Although SFPGetFile may have
  109.          * opened a WD, it is not clear that on faking an open that
  110.          * reply.vRefNum is set to a WD VRefNum.
  111.          */
  112.         memset(&wdpb, 0, sizeof(wdpb));
  113.         wdpb.ioCompletion = nil;
  114.         wdpb.ioNamePtr = nil;
  115.         wdpb.ioVRefNum = dirVRefNum;
  116.         wdpb.ioWDProcID = 0;
  117.         wdpb.ioWDDirID = dirDirID;
  118.         if (PBOpenWD(&wdpb, false) != noErr) {
  119.             OSAlert(routine, "\pPBOpenWD", nil, wdpb.ioResult);
  120.             return(false);
  121.         }
  122.         
  123.         dirVRefNum = wdpb.ioVRefNum;
  124.     }
  125.     
  126.     return(true);
  127. }
  128.  
  129. /*
  130.  * Return the working directory we allocated after a pseudo-selection
  131.  * on an extract.
  132.  */
  133.  
  134. void
  135. RlsDir()
  136. {
  137.     if (!dirSelected)
  138.         return;
  139.         
  140.     if (PBCloseWD(&wdpb, false) != noErr) {
  141.         OSAlert("\pRlsDir", "\pPBCloseWD", nil, wdpb.ioResult);
  142.         return;
  143.     }
  144. }